package com.hongyuan.sellcoach.ui.course.activity;

import android.os.Bundle;
import androidx.lifecycle.ViewModelProviders;
import com.hongyuan.sellcoach.R;
import com.hongyuan.sellcoach.base.AppViewModelFactory;
import com.hongyuan.sellcoach.base.CustomActivity;
import com.hongyuan.sellcoach.data.Constants;
import com.hongyuan.sellcoach.databinding.ActivityCalendarBinding;
import com.hongyuan.sellcoach.ui.course.adapter.CalendarPagerAdapter;
import com.hongyuan.sellcoach.ui.course.view_mode.CalendarViewMode;
import me.tatarka.bindingcollectionadapter2.BR;

public class CalendarActivity extends CustomActivity<ActivityCalendarBinding, CalendarViewMode> {

    private CalendarPagerAdapter adapter;

    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.activity_calendar;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public CalendarViewMode initViewModel() {
        AppViewModelFactory factory = AppViewModelFactory.getInstance(getApplication());
        return ViewModelProviders.of(this, factory).get(CalendarViewMode.class);
    }

    @Override
    public void initView() {
        super.initView();

        binding.comBack.setOnClickListener(view -> finish());

        adapter = new CalendarPagerAdapter(this,getSupportFragmentManager());
        binding.mViewPager.setAdapter(adapter);
        binding.mViewPager.setCurrentItem(0);
    }

    @Override
    public void initData() {
        super.initData();

        viewModel.requestData(Constants.GET_COACH_TIMEPLAN_LIST);
    }

    @Override
    public void initViewObservable() {
        super.initViewObservable();

        viewModel.uc.setDate.observe(this, lists -> {
            adapter.setData(lists);
        });
    }
}
